<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增招聘岗位')" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-recruitpost-add">
            <input name="postionAsso" type="hidden" id="treeId"/>
            <div class="form-group">    
                <label class="col-sm-3 control-label">岗位名称：</label>
                <div class="col-sm-8">
                    <input name="postionName" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">所属部门：</label>
                <!--<div class="col-sm-8">
                    <select name="postionAsso" class="form-control m-b" >
                        <option value="">&#45;&#45;请选择部门&#45;&#45;</option>
                        <option th:each="post:${posts}" th:value="${post.postId}" th:text="${post.postName}"></option>
                    </select>
                </div>-->
                <div class="col-sm-8">
                    <div class="input-group">
                        <input name="postionAssoName" onclick="selectDeptTree()" id="treeName" type="text" placeholder="请选择归属部门" class="form-control" required>
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">岗位类别：</label>
                <div class="col-sm-8">
                    <select name="recruitType" class="form-control m-b" >
                        <option value="">--请选择类别--</option>
                        <option th:each="type:${types}" th:value="${type.id}" th:text="${type.recuitName}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">工作地点：</label>
                <div class="col-sm-8">
                    <input name="workAddress" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">招聘人数：</label>
                <div class="col-sm-8">
                    <input name="recruitNum" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">招聘描述：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" name="recruitContent">
                    <div class="summernote" id="recruitContent"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">任职要求：</label>
                <div class="col-sm-8">
                    <textarea name="postionRequire" class="form-control"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">岗位职责：</label>
                <div class="col-sm-8">
                    <textarea name="postionResponse" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "ylyx/recruitpost"
        $("#form-recruitpost-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-recruitpost-add').serialize());
            }
        }

        $(function() {
            $('.summernote').summernote({
                lang: 'zh-CN',
                callbacks: {
                    onChange: function(contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function(files) {
                    	var obj = this;
                    	var data = new FormData();
                    	data.append("file", files[0]);
                    	$.ajax({
                    		type: "post",
                    		url: ctx + "common/upload",
                    		data: data,
                    		cache: false,
                    		contentType: false,
                    		processData: false,
                    		dataType: 'json',
                    		success: function(result) {
                    			if (result.code == web_status.SUCCESS) {
                    				$('#' + obj.id).summernote('insertImage', result.url);
                    			} else {
                    				$.modal.alertError(result.msg);
                    			}
                    		},
                    		error: function(error) {
                    			$.modal.alertWarning("图片上传失败。");
                    		}
                    	});
                    }
                }
            });
        });
        /* 用户管理-新增-选择部门树 */
        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
            }
        }
    </script>
</body>
</html>